package com.young.springboot.log.controller;

import com.young.springboot.log.entity.User;
import com.young.springboot.log.entity.jpa.UserEntity;
import com.young.springboot.log.mapper.UserMapper;
import com.young.springboot.log.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("log")
public class TestController {
   private Logger logger = LoggerFactory.getLogger(this.getClass());

   @Autowired
   private UserMapper userMapper;

   @Autowired
   private UserRepository userRepository;

    @RequestMapping("simple")
    public void simpleLog(){
        logger.debug("debug");
        logger.error("error");
        logger.warn("warn");
        logger.info("info");

        long start = System.currentTimeMillis();
        for (int i = 0; i < 200; i++) {
            logger.info("测试日志");
        }
        long end = System.currentTimeMillis();
    }


    @RequestMapping("p6spy/mybatis")
    public Object p6spyLog(){
        User user = userMapper.selectById(1);
        return user;
    }
    @RequestMapping("p6spy/jpa")
    public Object p6spyJpa(){
        UserEntity user = userRepository.findById(1).get();
        return user;
    }
}
